/*
 * 3.4
 * In the classic problem of the Towers of Hanoi, you have 3 rods and N disks of different
 * sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending
 * order of size from top to bottom (e.g., each disk sits on top of an even larger one). You
 * have the following constraints:
 * (A) Only one disk can be moved at a time.
 * (B) A disk is slid off the top of one rod onto the next rod.
 * (C) A disk can only be placed on top of a larger disk.
 * Write a program to move the disks from the first rod to the last using Stacks.
 */
#include <iostream>
#include <stack>

std::stack<int> s[3];

void hanoi(int from, int to, int helper, int count)
{
    if (count == 1) {
        int i = s[from].top();
        s[from].pop();
        s[to].push(i);
    } else {
        hanoi(from, helper, to, count-1);
        int i = s[from].top();
        s[from].pop();
        s[to].push(i);
        hanoi(helper, to, from, count-1);
    }
}

int main()
{
    for (int i = 7; i >= 1; i--) {
        s[0].push(i);
    }
    hanoi(0, 1, 2, 7);
    while (!s[1].empty()) {
        std::cout << s[1].top() << " ";
        s[1].pop();
    }
    std::cout << std::endl;
    return 0;
}
